<!DOCTYPE html>
<!-- saved from url=(0093)http://people.csail.mit.edu/dnj/teaching/6170/accelerator/modules/objects/code/account-2.html -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" href="../editor/codestyles.css">
    <script src="../editor/codeeditor.js"></script>
    <style>
    canvas {position: absolute; left: 580px; top: 67px}
    </style>    
</head>
<body>

<div id="buttons">
	<input type="submit" value="run" id="runIntro" onclick="slide.runCode();">
	<input type="submit" value="clear output" id="clearOutput" onclick="clearOutputBox();">
	<input type="submit" value="revert" id="reloadCode" onclick="location.reload();">
</div>

<canvas id="canvas" height="200" width="200"></canvas>

<script>
</script>

<textarea id="code" name="code" style="display: none;">var Account = function (bal) {
	return {
		balance: function () { console.log(bal);},
		deposit: function (x) {bal = bal + x;  console.log("yes");},
		withdraw: function (x) {
			if (bal &lt; x) { console.log("no");}
			else {bal = bal - x;  console.log("yes");}
			}
		}
	}
a = Account(100);
a.deposit(10); a.withdraw(130); a.balance();</textarea><div class="CodeMirror"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 8.99306px; left: 51.9907px;"><textarea style="position: absolute; padding: 0; width: 1px; height: 1em" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-default" tabindex="-1"><div style="position: relative; height: 273.76px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-gutter" style="height: 274px;"><div class="CodeMirror-gutter-text"><pre>&nbsp;1</pre><pre>2</pre><pre>3</pre><pre>4</pre><pre>5</pre><pre>6</pre><pre>7</pre><pre>8</pre><pre>9</pre><pre>10</pre><pre>11</pre><pre>12</pre></div></div><div class="CodeMirror-lines"><div style="position: relative; z-index: 0; outline: none; margin-left: 43px;"><div style="position: absolute; width: 100%; height: 0; overflow: hidden; visibility: hidden; outline: 5px auto none"></div><pre class="CodeMirror-cursor" style="top: 0px; left: 0px;">&nbsp;</pre><div style="position: relative; z-index: -1; display: none;"></div><div style=""><pre><span class="cm-keyword">var</span> <span class="cm-variable">Account</span> = <span class="cm-keyword">function</span> (<span class="cm-def">bal</span>) {</pre><pre><span class="cm-tab">    </span><span class="cm-keyword">return</span> {</pre><pre><span class="cm-tab">    </span><span class="cm-tab">    </span><span class="cm-property">balance</span>: <span class="cm-keyword">function</span> () {<span class="cm-variable"> console.log</span>(<span class="cm-variable-2">bal</span>);},</pre><pre><span class="cm-tab">    </span><span class="cm-tab">    </span><span class="cm-property">deposit</span>: <span class="cm-keyword">function</span> (<span class="cm-def">x</span>) {<span class="cm-variable-2">bal</span> = <span class="cm-variable-2">bal</span> + <span class="cm-variable-2">x</span>; <span class="cm-variable"> console.log</span>(<span class="cm-string">"yes"</span>);},</pre><pre><span class="cm-tab">    </span><span class="cm-tab">    </span><span class="cm-property">withdraw</span>: <span class="cm-keyword">function</span> (<span class="cm-def">x</span>) {</pre><pre><span class="cm-tab">    </span><span class="cm-tab">    </span><span class="cm-tab">    </span><span class="cm-keyword">if</span> (<span class="cm-variable-2">bal</span> &lt; <span class="cm-variable-2">x</span>) {<span class="cm-variable"> console.log</span>(<span class="cm-string">"no"</span>);}</pre><pre><span class="cm-tab">    </span><span class="cm-tab">    </span><span class="cm-tab">    </span><span class="cm-keyword">else</span> {<span class="cm-variable-2">bal</span> = <span class="cm-variable-2">bal</span> - <span class="cm-variable-2">x</span>; <span class="cm-variable"> console.log</span>(<span class="cm-string">"yes"</span>);}</pre><pre><span class="cm-tab">    </span><span class="cm-tab">    </span><span class="cm-tab">    </span>}</pre><pre><span class="cm-tab">    </span><span class="cm-tab">    </span>}</pre><pre><span class="cm-tab">    </span>}</pre><pre><span class="cm-variable">a</span> = <span class="cm-variable">Account</span>(<span class="cm-number">100</span>);</pre><pre><span class="cm-variable">a</span>.<span class="cm-property">deposit</span>(<span class="cm-number">10</span>); <span class="cm-variable">a</span>.<span class="cm-property">withdraw</span>(<span class="cm-number">130</span>); <span class="cm-variable">a</span>.<span class="cm-property">balance</span>();</pre></div></div></div></div></div></div></div>
<div id="output"><i>Output</i></div>



</body></html>